<!DOCTYPE html>
<html>
<head font_float=Fq9PYj >
    <meta charset="utf-8">
    <title>CMS供应商后台图库管理</title>
    <link type="text/css" href="/supplier/public/pc/css/supplier_pub.css" rel="stylesheet">
    <link type="text/css" href="/supplier/public/pc/css/supplier_back.css" rel="stylesheet">
    <link type="text/css" href="/supplier/public/pc/css/photo_style.css" rel="stylesheet">
    {Common::js("jquery.min.js,common.js,choose.js,layer/layer.js")}
    <link type="text/css" href="/tools/js/artDialog/css/ui-dialog.css" rel="stylesheet" />
    <link type="text/css" href="/tools/js/msgbox/msgbox.css" rel="stylesheet" />
    <script type="text/javascript" src="/tools/js/artDialog/dist/dialog-plus.js"></script>
    <script type="text/javascript" src="/tools/js/msgbox/msgbox.js"></script>
</head>
<body>
<div class="photo-manage-wrap">
    <div class="block-search-bar clearfix">
        <div class="fl select-box w105">
            <select name="photo_type" size="1" class="select">
                <option value="0">全部</option>
                <option value="1">文件夹</option>
                <option value="2">图片</option>
            </select>
        </div>
        <div class="fl ml-10">
            <input type="text" class="input-text w200 keyword" placeholder="文件夹名称/图片名称" value="">
            <input type="button" class="btn btn-default ml-5 pm-search-btn w80" value="查询">
        </div>
        <div class="fr">
            <a href="javascript:;" class="choose-btn" onclick="reduction_photo()">还原</a>
            <a href="javascript:;" class="choose-btn" onclick="refresh_photo()">刷新</a>
        </div>
    </div>
    <div class="photo-manage-content">
        <input type="hidden" name="level" value="2">
        <input type="hidden" name="group_id" value="">
        <ul class="recycle-list clearfix">

        </ul>
    </div>
</div>
<!-- 内容 -->


<script>
    $(function(){
        get_recycle_bin_data();
    })

    function reduction_photo()
    {
        var recycle_id = [];
        $('input[name="recycle_id[]"]:checked').each(function(){
            recycle_id.push($(this).val());
        })

        if(recycle_id.length==0){
            layer.msg('请选择要还原的相册或图片');
            return false;
        }

        $.ajax({
            type: 'post',
            url: '/supplier/pc/gallery/ajax_reduction_photo',
            data: {recycle_id:recycle_id},
            dataType: 'json',
            success: function (res) {
                if(res.status){
                    $('input[name="recycle_id[]"]:checked').parent().remove();
                }
            }
        })
    }

    function refresh_photo()
    {
        $('.keyword').val();
        $("[name='photo_type']").find('option').eq(0).prop('selected', true);
        var group_id = $("[name='group_id']").val();
        $('.recycle-list').html('');
        get_recycle_bin_data(group_id);
    }

    function get_recycle_bin_data()
    {
        $.ajax({
            type: 'post',
            url: '/supplier/pc/gallery/ajax_get_recycle_bin_data',
            dataType: 'json',
            success: function (res) {
                if(res.length>0){
                    for(var i=0;i<res.length;i++){
                        assemble_photo_img(res[i]);
                    }
                }
            }
        })
    }

    function assemble_photo_img(data)
    {
        var html = '<li>';
        html += '<input type="checkbox" name="recycle_id[]" class="reduction" value="'+data.id+'">';
        html += '<i class="choice-ico" onclick="delete_recycle('+data.id+',$(this))"></i>';
        html += '<div class="photo-img"><img src="'+data.url+'" alt=""></div>';
        html += '<div class="photo-name mt-10">';
        html += '<input type="text" class="input-text " value="'+data.name+'">';
        html += '</div>';
        html += '</li>';

        $('.recycle-list').append(html);
    }

    function delete_recycle(recycle_id,obj)
    {
        layer.confirm('确定彻底删除？', {
            btn: ['确定','取消'],
            yes: function (index) {
                $.ajax({
                    type: 'post',
                    url: '/supplier/pc/gallery/ajax_delete_recycle',
                    data: {recycle_id:recycle_id},
                    dataType: 'json',
                    success: function (res) {
                        if(res.status){
                            obj.parent().remove();
                        }else{
                            layer.msg(res.msg);
                        }
                    }
                })
                layer.close(index);
            }
        });
    }
</script>
</body>
</html>
